package com.zhengdongzulin.zuke.app.main.mine.doorlock

import androidx.lifecycle.rxLifeScope
import com.lxj.androidktx.livedata.StateLiveData
import com.zhengdongzulin.zuke.app.Api
import com.zhengdongzulin.zuke.base.BaseViewModel
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

class ChangeLockPwdVm : BaseViewModel() {

    var update_lock_key_password: StateLiveData<String> = StateLiveData()

    fun update_lock_key_password(houseId: String, code: String, newPassWord: String) {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.UPDATE_LOCK_KEY_PASSWORD)
                            .add("houseId", houseId)
                            .add("code", code)
                            .add("newPassWord", newPassWord)
                            .toResponse<String>()
                            .await()
                    update_lock_key_password.postValueAndSuccess(r)
                }, {
            assignment(it, update_lock_key_password)
        }
        )
    }

    var send_code: StateLiveData<String> = StateLiveData()

    fun send_code() {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.SEND_CODE)
                            .add("type", "4")
                            .add("phone", mShareViewModel!!.userInfo.value!!.phone)
                            .toResponse<String>()
                            .await()
                    send_code.postValueAndSuccess(r)
                }, {
            assignment(it, send_code)
        }
        )
    }

}